package com.freeman.cement.service.impl;

import com.freeman.cement.entity.ResponseResult;
import com.freeman.cement.exception.AppException;
import com.freeman.cement.exception.AppExceptionCodeMsg;
import com.freeman.cement.mapper.RoleDao;
import com.freeman.cement.entity.Role;
import com.freeman.cement.service.RoleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    //引用类型的自动注入@Autowired,@Resource
    @Resource
    private RoleDao roleDao;

    @Override
    public List<Role> selectAllRole() {
        return roleDao.selectAllRole();
    }

    @Override
    public ResponseResult selectRole(int pageNo, int pageSize) {
        if (pageNo < 1 || pageSize > 1000) {
            throw new AppException(AppExceptionCodeMsg.PAGE_NO_OR_SIZE_WRONG);
        } else {
            PageHelper.startPage(pageNo, pageSize, true);
            List<Role> depts = roleDao.selectList(null);
            PageInfo<Role> pageInfo = new PageInfo<Role>(depts);
            return ResponseResult.success(pageInfo);
        }
    }

}
